// Copyright (c) 2019 Presto Labs Pte. Ltd.
// Author: jaewon

#pragma once

#include <cstdint>

#include "coin1/fastfeed/view/base.h"

namespace fastfeed {
namespace view {
namespace detail {

class BookBuilderParameterHolder : public BuilderBase {
 public:
  ~BookBuilderParameterHolder() override = default;

  double price_multiplier() const { return price_multiplier_; }
  double qty_multiplier() const { return qty_multiplier_; }

 protected:
  bool OnBookBuilderParameter(const proto::Feed& feed);

 private:
  double price_multiplier_ = 0;
  double qty_multiplier_ = 0;
};  // class BookBuilderParameterHolder

}  // namespace detail

class TradeBuilder : public detail::BookBuilderParameterHolder {
 public:
  ~TradeBuilder() final = default;

  void Init(ViewCollection* view_collection) final;
  bool UpdateByProto(const proto::Feed& feed) final;

  // View methods
  int64_t price() const { return price_; }
  int64_t qty() const { return qty_; }
  proto::TradeSide side() const { return side_; }
  bool has_more_trade() const { return has_more_trade_; }

 private:
  bool OnTrade(const proto::Feed& feed);
  bool OnIndex(const proto::Feed& feed);

  int64_t price_ = 0;
  int64_t qty_ = 0;
  bool has_more_trade_ = false;
  proto::TradeSide side_ = proto::TRADE_SIDE_INVALID;
};  // class TradeBuilder

}  // namespace view
}  // namespace fastfeed
